package com.library.mapper;

import com.github.pagehelper.Page;
import com.library.annotation.AutoFill;
import com.library.dto.CategoryPageQueryDTO;
import com.library.entity.Category;
import com.library.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface CategoryMapper {

    /**
     * 插入数据
     * @param category
     */
    @Insert("insert into category(name, description, status, create_time, update_time)" +
            " VALUES" +
            "(#{name}, #{description},#{status}, #{createTime}, #{updateTime})"
            )
    @AutoFill(value = OperationType.INSERT)
    void insert(Category category);

    /**
     * 分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);

    /**
     * 修改
     * @param category
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Category category);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from category where id = #{id}")
    Category getById(Long id);

    /**
     * 根据id删除
     * @param id
     */
    @Delete("delete from category where id = #{id}")
    void deleteById(Long id);
}
